package com.cz.modules.jxc.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cz.common.utils.DateUtils;
import com.cz.common.utils.SellMasterUtil;
import com.cz.modules.cll.entity.CllVehicleRecordEntity;
import com.cz.modules.cll.service.CllVehicleRecordService;
import com.cz.modules.jxc.entity.JxcSellDetailsEntity;
import com.cz.modules.jxc.entity.JxcShopEntity;
import com.cz.modules.jxc.service.JxcSellDetailsService;
import com.cz.modules.jxc.service.JxcShopService;
import com.cz.modules.rll.entity.RllHourCountEntity;
import com.cz.modules.rll.entity.RllPlaceEntity;
import com.cz.modules.rll.service.RllHourCountService;
import com.cz.modules.rll.service.RllPlaceService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonObject;
import org.apache.commons.lang.StringUtils;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cz.common.utils.PageUtils;
import com.cz.common.utils.Query;

import com.cz.modules.jxc.dao.JxcSaleOrderDao;
import com.cz.modules.jxc.entity.JxcSaleOrderEntity;
import com.cz.modules.jxc.service.JxcSaleOrderService;


@Service("jxcSaleOrderService")
public class JxcSaleOrderServiceImpl extends ServiceImpl<JxcSaleOrderDao, JxcSaleOrderEntity> implements JxcSaleOrderService {
    @Autowired
    private JxcSellDetailsService sellDetailsService;
    @Autowired
    private JxcSaleOrderService jxcSaleOrderService;
    @Autowired
    private CllVehicleRecordService cllVehicleRecordService;
    @Autowired
    private RllHourCountService rllHourCountService;
    @Autowired
    private RllPlaceService rllPlaceService;
    @Autowired
    private JxcShopService jxcShopService;
    @Override
    public List shopSaleCount(String startTime, String endTime) {
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }
        List list=new ArrayList();
        //所有商户
        List<JxcShopEntity> shoplist=jxcShopService.list();
        //该时间段所有订单
        List<JxcSaleOrderEntity> orderlist=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                .ge("sell_master_date",startTime)
                .le("sell_master_date",endTime)
        );

        List<String> shopName=new ArrayList();
        for (JxcShopEntity en:shoplist) {
            shopName.add(en.getShopName());
        }
        List<String> str=new ArrayList();
        List<JxcSaleOrderEntity> order=new ArrayList();
        for (String time:timeStrList) {
            for (JxcSaleOrderEntity en:orderlist) {
                String tt=DateUtil.format(en.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    en.setName(time);
                    order.add(en);
                }
            }
            str.add(time);
        }
        list.add(order);
        list.add(str);
        list.add(shopName);
        return list;
    }
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String sellMasterCode= (String) params.get("sellMasterCode");
        IPage<JxcSaleOrderEntity> page = this.page(
                new Query<JxcSaleOrderEntity>().getPage(params),
                new QueryWrapper<JxcSaleOrderEntity>()
                        .like(StringUtils.isNotBlank(sellMasterCode),"sell_master_code",sellMasterCode)
                        .orderByDesc("sell_master_date")
        );
        return new PageUtils(page);
    }
    @Override
    public List averagePricehour(String startTime, String endTime) {
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            calendar.add(Calendar.HOUR,1);
            timeList.add(calendar.getTimeInMillis());
        }

        /******************销售额************************/
        List<JxcSaleOrderEntity> selllist=jxcSaleOrderService.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",startTime)
                        .le("sell_master_date",endTime)
        );
        List<String> salevalueList=new ArrayList<>();
        Long s=start;
        List<String> timeStrList=new ArrayList<>();
        for (int i = 0; i <timeList.size() ; i++) {//销售额数据
            timeStrList.add(DateUtil.format(new Date(timeList.get(i)),"HH:mm"));
            Double salecount=0D;//该时间段销售额
            Double rllcount=0D;//该时间段客流量
            for (JxcSaleOrderEntity record:selllist) {
                Long crossTime=record.getSellMasterDate().getTime();
                if(crossTime>=s && crossTime<timeList.get(i)){
                    salecount +=(record.getCashPay()+record.getMobilePay()+record.getBankPay());
                    rllcount ++;
                }
            }

           if(rllcount ==0){
               rllcount=1D;
           }
            s=timeList.get(i);
            //运算
            DecimalFormat df = new DecimalFormat("0.00");
            String avg = df.format((Double) salecount/rllcount);
            salevalueList.add(avg);
        }
        List list=new ArrayList();
        list.add(timeStrList);
        list.add(salevalueList);
        return list;
    }

    @Override
    public List averagePriceday(String startTime, String endTime) {
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }

        /******************销售额************************/
        List<JxcSaleOrderEntity> selllist=jxcSaleOrderService.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",startTime)
                        .le("sell_master_date",endTime)
        );
        List<String> salevalueList=new ArrayList<>();
        for (String time:timeStrList) {
            Double salecount=0D;
            int rllcount=0;
            for (JxcSaleOrderEntity record:selllist) {
                String tt=DateUtil.format(record.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    salecount +=(record.getCashPay()+record.getBankPay()+record.getMobilePay());
                    rllcount++;
                }
            }
            /*for (RllHourCountEntity record:rllcountlist) {
                String tt=DateUtil.format(record.getStartTime(),"MM-dd");
                if(tt.equals(time)){
                    rllcount +=record.getEnterNum();
                }
            }*/
            if(rllcount == 0){
                rllcount=1;
            }
            //运算
            DecimalFormat df = new DecimalFormat("0.00");
            String avg = df.format(salecount/rllcount);
            salevalueList.add(avg);
        }
        List list=new ArrayList();
        list.add(timeStrList);
        list.add(salevalueList);
        return list;
    }

    @Override
    public List southAndNorthAveragePriceDay(List<JxcShopEntity> shopList,String startTime, String endTime) {
        List<String> shopCodeList=new ArrayList<>();
        for (JxcShopEntity shop :shopList) {
            shopCodeList.add(shop.getShopCode());
        }
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }

        /******************销售额************************/
        List<JxcSaleOrderEntity> selllist=jxcSaleOrderService.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",startTime)
                        .le("sell_master_date",endTime)
                        .in("shop_code",shopCodeList)
        );
        List<Double> salevalueList=new ArrayList<>();
        for (String time:timeStrList) {
            Double salecount=0D;
            int rllcount=0;
            for (JxcSaleOrderEntity record:selllist) {
                String tt=DateUtil.format(record.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    salecount +=(record.getCashPay()+record.getBankPay()+record.getMobilePay());
                    rllcount++;
                }
            }
            /*for (RllHourCountEntity record:rllcountlist) {
                String tt=DateUtil.format(record.getStartTime(),"MM-dd");
                if(tt.equals(time)){
                    rllcount +=record.getEnterNum();
                }
            }*/
            if(rllcount == 0){
                rllcount=1;
            }
            //运算
            DecimalFormat df = new DecimalFormat("0.00");
            String avg = df.format(salecount/rllcount);
            Double dzg=Double.parseDouble(avg);
            salevalueList.add(dzg);
        }
        List list=new ArrayList();
        list.add(timeStrList);
        list.add(salevalueList);
        return list;
    }

    @Override
    public Map<String,List> salerllhour(String startTime, String endTime) {
        Map<String,List> map=new HashMap<>();
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            calendar.add(Calendar.HOUR,1);
            timeList.add(calendar.getTimeInMillis());
        }
        //该时间段客流 所有卡口 去除厕所
        List<JxcSaleOrderEntity> list2=new ArrayList<>();
        List<RllPlaceEntity> placelist=rllPlaceService.list(
                new QueryWrapper<RllPlaceEntity>()
                        .eq("type","0")
        );
        List<String> placeid=new ArrayList<>();
        for (RllPlaceEntity place:placelist) {
            placeid.add(place.getId());
        }
        /******************客流************************/
        List<RllHourCountEntity> rllcountlist=rllHourCountService.list(
                new QueryWrapper<RllHourCountEntity>()
                        .ge("start_time",startTime)
                        .le("start_time",endTime)
                        .in("place_id",placeid)
        );
        List<Integer> rllvalueList=new ArrayList<>();
        Long s1=start;
        for (int i = 0; i <timeList.size() ; i++) {//客流数据
            int count=0;
            for (RllHourCountEntity record:rllcountlist) {
                Long crossTime=record.getStartTime().getTime();
                if(crossTime>=s1 && crossTime<timeList.get(i)){
                    count +=record.getEnterNum();
                }
            }
            s1=timeList.get(i);
            rllvalueList.add(count);
        }
        map.put("客流量",rllvalueList);

        /******************销售额************************/
        List<JxcSaleOrderEntity> selllist=jxcSaleOrderService.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",startTime)
                        .le("sell_master_date",endTime)
        );
        List salevalueList=new ArrayList<>();
        Long s=start;
        List<String> timeStrList=new ArrayList<>();
        for (int i = 0; i <timeList.size() ; i++) {//销售额数据
            timeStrList.add(DateUtil.format(new Date(timeList.get(i)),"HH:mm"));
            Double count=0D;
            for (JxcSaleOrderEntity record:selllist) {
                Long crossTime=record.getSellMasterDate().getTime();
                if(crossTime>=s && crossTime<timeList.get(i)){
                    count +=(record.getCashPay()+record.getBankPay()+record.getMobilePay());
                }
            }
            s=timeList.get(i);
            salevalueList.add(count);
        }
        List list=new ArrayList();
        list.add(timeStrList);
        list.add(salevalueList);;
        map.put("销售额",list);
        return map;
    }

    @Override
    public Map<String, List> salerllday(String startTime, String endTime) {
        Map<String,List> map=new HashMap<>();
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }
        /******************客流************************/
        List<JxcSaleOrderEntity> list2=new ArrayList<>();
        List<RllPlaceEntity> placelist=rllPlaceService.list(
                new QueryWrapper<RllPlaceEntity>()
                        .eq("type","0")
        );
        List<String> placeid=new ArrayList<>();
        for (RllPlaceEntity place:placelist) {
            placeid.add(place.getId());
        }
        List<RllHourCountEntity> rllcountlist=rllHourCountService.list(
                new QueryWrapper<RllHourCountEntity>()
                        .ge("start_time",startTime)
                        .le("start_time",endTime)
                        .in("place_id",placeid)
        );
        List<Integer> rlvalueList=new ArrayList<>();
        for (String time:timeStrList) {
            int count=0;
            for (RllHourCountEntity record:rllcountlist) {
                String tt=DateUtil.format(record.getStartTime(),"MM-dd");
                if(tt.equals(time)){
                    count +=record.getEnterNum();
                }
            }
            rlvalueList.add(count);
        }
        List list3=new ArrayList();
        list3.add(rlvalueList);
        map.put("客流量",rlvalueList);
        /******************销售额************************/
        List<JxcSaleOrderEntity> selllist=jxcSaleOrderService.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",startTime)
                        .le("sell_master_date",endTime)
        );
        List sevalueList=new ArrayList<>();
        for (String time:timeStrList) {
            Double count=0D;
            for (JxcSaleOrderEntity record:selllist) {
                String tt=DateUtil.format(record.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    count +=(record.getBankPay()+record.getCashPay()+record.getMobilePay());
                }
            }
            sevalueList.add(count);
        }
        List list1=new ArrayList();
        list1.add(timeStrList);
        list1.add(sevalueList);
        map.put("销售额",list1);
        return map;
    }
    @Override
    public Map<String,List> salecllrllhour(String startTime, String endTime) {
        Map<String,List> map=new HashMap<>();
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            calendar.add(Calendar.HOUR,1);
            timeList.add(calendar.getTimeInMillis());
        }
        //该时间段客流 所有卡口 去除厕所
        List<JxcSaleOrderEntity> list2=new ArrayList<>();
        List<RllPlaceEntity> placelist=rllPlaceService.list(
                new QueryWrapper<RllPlaceEntity>()
                        .eq("type","0")
        );
        List<String> placeid=new ArrayList<>();
        for (RllPlaceEntity place:placelist) {
            placeid.add(place.getId());
        }
       /******************车流************************/
        String monitoringid[]={"1bd4530bfe534770a11ea196b34663fc","095852b3f7c948d6b27d5fd698bd1c37"};
        List<CllVehicleRecordEntity> clllist= cllVehicleRecordService.list(
                new QueryWrapper<CllVehicleRecordEntity>()
                        .ge("cross_time",startTime)
                        .le("cross_time",endTime)
                        .in("monitoring_id",Arrays.asList(monitoringid))
        );
        List<Integer> cllvalueList=new ArrayList<>();
        Long s2=start;
        for (int i = 0; i <timeList.size() ; i++) {//客流数据
            int count=0;
            for (CllVehicleRecordEntity record:clllist) {
                Long crossTime=record.getCrossTime().getTime();
                if(crossTime>=s2 && crossTime<timeList.get(i)){
                    count ++;
                }
            }
            s2=timeList.get(i);
            cllvalueList.add(count);
        }
        map.put("车流量",cllvalueList);
        /******************客流************************/
        List<RllHourCountEntity> rllcountlist=rllHourCountService.list(
                new QueryWrapper<RllHourCountEntity>()
                        .ge("start_time",startTime)
                        .le("start_time",endTime)
                        .in("place_id",placeid)
        );
        List<Integer> rllvalueList=new ArrayList<>();
        Long s1=start;
        for (int i = 0; i <timeList.size() ; i++) {//客流数据
            int count=0;
            for (RllHourCountEntity record:rllcountlist) {
                Long crossTime=record.getStartTime().getTime();
                if(crossTime>=s1 && crossTime<timeList.get(i)){
                    count +=record.getEnterNum();
                }
            }
            s1=timeList.get(i);
            rllvalueList.add(count);

        }
        map.put("客流量",rllvalueList);

        /******************销售额************************/
        List<JxcSaleOrderEntity> selllist=jxcSaleOrderService.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",startTime)
                        .le("sell_master_date",endTime)
        );
        List salevalueList=new ArrayList<>();
        Long s=start;
        List<String> timeStrList=new ArrayList<>();
        for (int i = 0; i <timeList.size() ; i++) {//销售额数据
            timeStrList.add(DateUtil.format(new Date(timeList.get(i)),"HH:mm"));
            Double count=0D;
            for (JxcSaleOrderEntity record:selllist) {
                Long crossTime=record.getSellMasterDate().getTime();
                if(crossTime>=s && crossTime<timeList.get(i)){
                    count +=(record.getCashPay()+record.getBankPay()+record.getMobilePay());
                }
            }
            s=timeList.get(i);
            salevalueList.add(count);
        }
        List list=new ArrayList();
        list.add(timeStrList);
        list.add(salevalueList);;
        map.put("销售额",list);
        return map;
    }

    @Override
    public Map<String, List> salecllrllday(String startTime, String endTime) {
        Map<String,List> map=new HashMap<>();
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }
        /******************车流************************/
        String monitoringid[]={"1bd4530bfe534770a11ea196b34663fc","095852b3f7c948d6b27d5fd698bd1c37"};
        List<CllVehicleRecordEntity> clllist= cllVehicleRecordService.list(
                new QueryWrapper<CllVehicleRecordEntity>()
                        .ge("cross_time",startTime)
                        .le("cross_time",endTime)
                        .in("monitoring_id",Arrays.asList(monitoringid))
        );
        List<Integer> clvalueList=new ArrayList<>();
        for (String time:timeStrList) {
            int count=0;
            for (CllVehicleRecordEntity record:clllist) {
                String tt=DateUtil.format(record.getCrossTime(),"MM-dd");
                if(tt.equals(time)){
                    count ++;
                }
            }
            clvalueList.add(count);
        }
        map.put("车流量",clvalueList);
        /******************客流************************/
        List<JxcSaleOrderEntity> list2=new ArrayList<>();
        List<RllPlaceEntity> placelist=rllPlaceService.list(
                new QueryWrapper<RllPlaceEntity>()
                        .eq("type","0")
        );
        List<String> placeid=new ArrayList<>();
        for (RllPlaceEntity place:placelist) {
            placeid.add(place.getId());
        }
        List<RllHourCountEntity> rllcountlist=rllHourCountService.list(
                new QueryWrapper<RllHourCountEntity>()
                        .ge("start_time",startTime)
                        .le("start_time",endTime)
                        .in("place_id",placeid)
        );
        List<Integer> rlvalueList=new ArrayList<>();
        for (String time:timeStrList) {
            int count=0;
            for (RllHourCountEntity record:rllcountlist) {
                String tt=DateUtil.format(record.getStartTime(),"MM-dd");
                if(tt.equals(time)){
                    count +=record.getEnterNum();
                }
            }
            rlvalueList.add(count);
        }
        map.put("客流量",rlvalueList);
        /******************销售额************************/
        List<JxcSaleOrderEntity> selllist=jxcSaleOrderService.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",startTime)
                        .le("sell_master_date",endTime)
        );
        List sevalueList=new ArrayList<>();
        for (String time:timeStrList) {
            Double count=0D;
            for (JxcSaleOrderEntity record:selllist) {
                String tt=DateUtil.format(record.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    count +=(record.getBankPay()+record.getCashPay()+record.getMobilePay());
                }
            }
            sevalueList.add(count);
        }
        List list1=new ArrayList();
        list1.add(timeStrList);
        list1.add(sevalueList);
        map.put("销售额",list1);
        return map;
    }
    @Override
    public Map<String, List<JxcSaleOrderEntity>> salecllrll() {
        Map<String, List<JxcSaleOrderEntity>> map=new HashMap<>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Date date=new Date();
        /*****************用来查询的时间**********************/
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(date);
        calendar1.add(Calendar.DAY_OF_MONTH, -1);
        calendar1.set(Calendar.MINUTE, 0);
        calendar1.set(Calendar.SECOND, 0);
        calendar1.set(Calendar.MILLISECOND, 0);
        String beginTime=df.format(calendar1.getTime());//24小时前的时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, 1);//1小时后
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String endtime=df.format(calendar.getTime());//1小时后的时间
        /*****************用来查询的时间**********************/
        List<String> timelist=new ArrayList<>();
        for (int i = 0; i <24; i++) {//将时间段都放入集合中
            Calendar calendar2=Calendar.getInstance();
            calendar2.setTime(date);
            calendar2.add(Calendar.HOUR_OF_DAY, -i);
            timelist.add(df.format(calendar2.getTime()));
        }
        List<JxcSaleOrderEntity> list=new ArrayList<>();
        //24小时销售额
        List<JxcSellDetailsEntity> selllist=sellDetailsService.list(
                new QueryWrapper<JxcSellDetailsEntity>()
                .ge("sell_master_date",beginTime)
                .lt("sell_master_date",endtime)
        );
        for (String time:timelist) {
            int count=0;
            for (JxcSellDetailsEntity sale:selllist) {
                if(time.substring(0,13).equals(df.format(sale.getSellMasterDate()).substring(0,13))){
                    count +=sale.getSellAmount();
                }
            }
            JxcSaleOrderEntity en=new JxcSaleOrderEntity();
            en.setName(time.substring(11,13));
            en.setYvalue(count);
            list.add(en);
        }
        map.put("销售额",list);
        //24小时车流量 只统计进口的
        List<JxcSaleOrderEntity> list1=new ArrayList<>();
        String monitoringid[]={"095852b3f7c948d6b27d5fd698bd1c37","1bd4530bfe534770a11ea196b34663fc"};
       List<CllVehicleRecordEntity> clllist= cllVehicleRecordService.list(
               new QueryWrapper<CllVehicleRecordEntity>()
               .ge("cross_time",beginTime)
               .le("cross_time",endtime)
               .in("monitoring_id",Arrays.asList(monitoringid))
       );
        for (String time:timelist) {
            int count=0;
            for (CllVehicleRecordEntity cll:clllist) {
                if(time.substring(0,13).equals(df.format(cll.getCrossTime()).substring(0,13))){
                    count ++;
                }
            }
            JxcSaleOrderEntity en=new JxcSaleOrderEntity();
            en.setName(time.substring(11,13));
            en.setYvalue(count);
            list1.add(en);
        }
        map.put("车流量",list1);
        //24小时客流量
        //所有卡口 去除厕所
        List<JxcSaleOrderEntity> list2=new ArrayList<>();
        List<RllPlaceEntity> placelist=rllPlaceService.list(
                new QueryWrapper<RllPlaceEntity>()
                        .eq("type","0")
        );
        List<String> placeid=new ArrayList<>();
        for (RllPlaceEntity place:placelist) {
            placeid.add(place.getId());
        }
        //该卡口所有数据
        List<RllHourCountEntity> rllcountlist=rllHourCountService.list(
                new QueryWrapper<RllHourCountEntity>()
                        .ge("start_time",beginTime)
                        .lt("start_time",endtime)
                        .in("place_id",placeid)
        );
        for (String time:timelist) {
            int count =0;
            for (RllHourCountEntity rll:rllcountlist) {
                if(time.substring(0,13).equals(df.format(rll.getStartTime()).substring(0,13))){
                    count +=rll.getEnterNum();
                }
            }
            JxcSaleOrderEntity en=new JxcSaleOrderEntity();
            en.setName(time.substring(11,13));
            en.setYvalue(count);
            list2.add(en);
        }
        map.put("客流量",list2);
        return map;
    }

    @Override
    public List<JxcSaleOrderEntity> hourTodaySalesvolume(String deptId, String type) {
        List<JxcSaleOrderEntity> list=new ArrayList<>();
        //该部门所有商户
        List<JxcShopEntity> shoplist=jxcShopService.list(
                new QueryWrapper<JxcShopEntity>()
                        .eq("dept_id",deptId)
        );
        List<String> shopcode=new ArrayList<>();//所有商户编码
        for (JxcShopEntity shop:shoplist) {
            shopcode.add(shop.getShopCode());
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String beginTime = null;
        String endTime = null;
        /*****************用来查询的时间**********************/
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());//用来查询
        if("0".equals(type)){
            beginTime=df.format(calendar.getTime())+" 00:00:00";//今天零点
            endTime = df1.format(calendar.getTime());//现在
        }
        //今天所有销售记录
        List<JxcSaleOrderEntity> salelist=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",beginTime)
                        .le("sell_master_date",endTime)
                        .in("shop_code",shopcode)
        );
        for (JxcShopEntity shop:shoplist) {
            int count=0;
            for (JxcSaleOrderEntity order:salelist) {
                if(order.getShopCode().equals(shop.getShopCode())){
                    count +=order.getTotalAmount();
                }
            }
            JxcSaleOrderEntity en=new JxcSaleOrderEntity();
            en.setName(shop.getShopName());
            en.setYvalue(count);
            list.add(en);
        }
        return list;
    }
    @Override
    public List salehour(String deptId, String startTime, String endTime) {

        //该部门所有商户
        List<JxcShopEntity> shoplist=jxcShopService.list(
                new QueryWrapper<JxcShopEntity>()
                        .eq("dept_id",deptId)
        );
        List<String> shopcode=new ArrayList<>();//所有商户编码
        for (JxcShopEntity shop:shoplist) {
            shopcode.add(shop.getShopCode());
        }
        List<JxcSaleOrderEntity> salelist=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .le("sell_master_date",endTime)
                        .ge("sell_master_date",startTime)
                        .in("shop_code",shopcode)
        );
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            calendar.add(Calendar.HOUR,1);
            timeList.add(calendar.getTimeInMillis());
        }
        List<Double> valueList=new ArrayList<>();
        Long s=start;
        List<String> timeStrList=new ArrayList<>();
        for (int i = 0; i <timeList.size() ; i++) {
            timeStrList.add(DateUtil.format(new Date(timeList.get(i)),"HH:mm"));
            Double count=0D;
            for (JxcSaleOrderEntity record:salelist) {
                Long crossTime=record.getSellMasterDate().getTime();
                if(crossTime>=s && crossTime<timeList.get(i)){
                    count +=record.getCashPay();
                    count +=record.getMobilePay();
                    count +=record.getBankPay();
                }
            }
            s=timeList.get(i);
            valueList.add(count);
        }
        List list=new ArrayList();
        list.add(timeStrList);
        list.add(valueList);
        return list;
    }

    @Override
    public List saleday(String deptId, String startTime, String endTime) {

        //该部门所有商户
        List<JxcShopEntity> shoplist=jxcShopService.list(
                new QueryWrapper<JxcShopEntity>()
                        .eq("dept_id",deptId)
        );
        List<String> shopcode=new ArrayList<>();//所有商户编码
        for (JxcShopEntity shop:shoplist) {
            shopcode.add(shop.getShopCode());
        }
        List<JxcSaleOrderEntity> salelist=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .le("sell_master_date",endTime)
                        .ge("sell_master_date",startTime)
                        .in("shop_code",shopcode)
        );
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        List<Double> valueList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }
        for (String time:timeStrList) {
            Double count=0D;
            for (JxcSaleOrderEntity record:salelist) {
                String tt=DateUtil.format(record.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    count +=record.getTotalAmount();
                }
            }
            valueList.add(count);
        }
        List list=new ArrayList();
        list.add(timeStrList);
        list.add(valueList);
        return list;
    }



    @Override
    public JxcSaleOrderEntity xseCount(String startTime, String endTime, List<String> shopCodeList) {
        return this.baseMapper.xseCount(startTime,endTime,shopCodeList);
    }

    @Override
    public Double orderCount(List<JxcShopEntity> shopList, String startTime, String endTime) {
        List<String> shopCodeList=new ArrayList<>();
        for (JxcShopEntity shop :shopList) {
            shopCodeList.add(shop.getShopCode());
        }
        List<JxcSaleOrderEntity> list=this.list(new QueryWrapper<JxcSaleOrderEntity>().ge("sell_master_date",startTime).le("sell_master_date",endTime).in("shop_code",shopCodeList));
        Double count=0D;
        for (JxcSaleOrderEntity order:list) {
            count+=order.getBankPay();
            count+=order.getCashPay();
            count+=order.getMobilePay();
        }
        java.text.DecimalFormat df=new java.text.DecimalFormat("#.00");

        return Double.parseDouble(df.format(count));
    }

    @Override
    public List orderCountlist(List<JxcShopEntity> shopList, String startTime, String endTime) {
        List list=new ArrayList();
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }

        List<String> shopCodeList=new ArrayList<>();
        for (JxcShopEntity shop :shopList) {
            shopCodeList.add(shop.getShopCode());
        }
        List<JxcSaleOrderEntity> salelist=this.list(new QueryWrapper<JxcSaleOrderEntity>().ge("sell_master_date",startTime).le("sell_master_date",endTime).in("shop_code",shopCodeList));
        for (String time:timeStrList) {
            Double count=0D;
            for (JxcSaleOrderEntity sale:salelist) {
                String tt=DateUtil.format(sale.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    count +=sale.getTotalAmount();
                }
            }
            list.add(count);
        }
        return list;
    }

    @Override
    public Integer orderSize(List<JxcShopEntity> shopList, String startTime, String endTime) {
        List<String> shopCodeList=new ArrayList<>();
        for (JxcShopEntity shop :shopList) {
            shopCodeList.add(shop.getShopCode());
        }
        List<JxcSaleOrderEntity> list=this.list(new QueryWrapper<JxcSaleOrderEntity>().ge("sell_master_date",startTime).le("sell_master_date",endTime).in("shop_code",shopCodeList));
        return list.size();
    }

    @Override
    public List orderSizelist(List<JxcShopEntity> shopList, String startTime, String endTime) {
        List list=new ArrayList();
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }

        List<String> shopCodeList=new ArrayList<>();
        for (JxcShopEntity shop :shopList) {
            shopCodeList.add(shop.getShopCode());
        }
        List<JxcSaleOrderEntity> salelist=this.list(new QueryWrapper<JxcSaleOrderEntity>().ge("sell_master_date",startTime).le("sell_master_date",endTime).in("shop_code",shopCodeList));
        for (String time:timeStrList) {
            int count=0;
            for (JxcSaleOrderEntity sale:salelist) {
                String tt=DateUtil.format(sale.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    count ++;
                }
            }
            list.add(count);
        }
        return list;
    }

    @Override
    public List proportionOfConsumers(String deptId, String startTime, String endTime) {
        List list=new ArrayList();
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
        }
        //该部门所有商户
        List<JxcShopEntity> shoplist=jxcShopService.list(
                new QueryWrapper<JxcShopEntity>()
                        .eq("dept_id",deptId)
        );
        List<String> shopcode=new ArrayList<>();//所有商户编码
        for (JxcShopEntity shop:shoplist) {
            shopcode.add(shop.getShopCode());
        }
        //所有订单
        List<JxcSaleOrderEntity> salelist=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .le("sell_master_date",endTime)
                        .ge("sell_master_date",startTime)
                        .in("shop_code",shopcode)
        );
        //该时间段客流量
        //所有卡口 去除厕所
        String areaName=null;
        if("3".equals(deptId)){
            areaName="南区" ;
        }else if("4".equals(deptId)){
            areaName="北区" ;
        }
        List<RllPlaceEntity> placelist=rllPlaceService.list(
                new QueryWrapper<RllPlaceEntity>()
                        .eq("type","0")
                        .eq("area",areaName)
        );
        List<String> placeid=new ArrayList<>();
        for (RllPlaceEntity place:placelist) {
            placeid.add(place.getId());
        }
        //该卡口所有数据
        List<RllHourCountEntity> rllcountlist=rllHourCountService.list(
                new QueryWrapper<RllHourCountEntity>()
                        .ge("start_time",startTime)
                        .lt("start_time",endTime)
                        .in("place_id",placeid)
        );
        for (String time:timeStrList) {
            int scount=0;
            int rcount=0;
            for (JxcSaleOrderEntity sale:salelist) {
                String tt=DateUtil.format(sale.getSellMasterDate(),"MM-dd");
                if(tt.equals(time)){
                    scount ++;
                }
            }
            for (RllHourCountEntity rll:rllcountlist) {
                String tt=DateUtil.format(rll.getStartTime(),"MM-dd");
                if(tt.equals(time)){
                    rcount +=rll.getEnterNum();
                }
            }
            if(rcount ==0){
                rcount=1;
            }
            DecimalFormat dff=new DecimalFormat("0.00");//设置保留位数
            String xfrczb= dff.format(((float)scount/(float)rcount)*100);
            Double dzg=Double.parseDouble(xfrczb);
            list.add(dzg);
        }
        return list;
    }

    @Override
    public List orderChart(List<JxcShopEntity> shopList, String startTime, String endTime) {

        List<String> shopCodeList=new ArrayList<>();
        for (JxcShopEntity shop :shopList) {
            shopCodeList.add(shop.getShopCode());
        }
        List<JxcSaleOrderEntity> orderList=this.list(new QueryWrapper<JxcSaleOrderEntity>().ge("sell_master_date",startTime+" 00:00:00").le("sell_master_date",endTime+" 23:59:59").in("shop_code",shopCodeList));
        //时间集合
        Long start= DateUtil.parse(startTime).getTime();
        Long end=DateUtil.parse(endTime).getTime();
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date(start));
        List<Long> timeList=new ArrayList<>();
        for (Long i = start; i <=end ; i=calendar.getTimeInMillis()) {
            timeList.add(calendar.getTimeInMillis());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }
        List<String> timeStrList=new ArrayList<>();
        List<String> valueList=new ArrayList<>();
        java.text.DecimalFormat df=new java.text.DecimalFormat("#0.00");
        for (Long ltime:timeList) {
            timeStrList.add(DateUtil.format(new Date(ltime),"MM-dd"));
            Double value=0D;
            for (JxcSaleOrderEntity order:orderList) {
                if(DateUtil.format(order.getSellMasterDate(),"yyyy-MM-dd").equals(DateUtil.format(new Date(ltime),"yyyy-MM-dd"))){
                    value+=order.getBankPay();
                    value+=order.getCashPay();
                    value+=order.getMobilePay();
                }
            }
            valueList.add(df.format(value));
        }
        List list=new ArrayList();
        list.add(timeStrList);
        list.add(valueList);
        return list;
    }

    @Override
    public List<JxcSaleOrderEntity> hourTodaySale(String deptId, String type) {
        List<JxcSaleOrderEntity> list=new ArrayList<>();
        //该部门所有商户
        List<JxcShopEntity> shoplist=jxcShopService.list(
                new QueryWrapper<JxcShopEntity>()
                        .eq("dept_id",deptId)
        );
        List<String> shopcode=new ArrayList<>();//所有商户编码
        for (JxcShopEntity shop:shoplist) {
            shopcode.add(shop.getShopCode());
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        SimpleDateFormat df2 = new SimpleDateFormat("HH");//设置日期格式
        Date date=new Date();
        String end = df2.format(date);
        List<String> timelist=new ArrayList<>();
        for (int i = 0; i <Integer.parseInt(end)+1; i++) {//将时间段都放入集合中
            Calendar calendar=Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.HOUR_OF_DAY, -(i-1));//i小时后
            timelist.add(df.format(calendar.getTime()));
        }

        /*****************用来查询的时间**********************/
        String beginTime = null;
        String endtime = null;
        if("0".equals(type)){
            Calendar calendar1 = Calendar.getInstance();
            beginTime=df1.format(calendar1.getTime())+" 00:00:00";//今天零点
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.HOUR_OF_DAY, 1);//1小时后
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            endtime=df.format(calendar.getTime());//1小时后的时间
        }

        /*****************用来查询的时间**********************/
        //24小时内的所有销售数据
        List<JxcSaleOrderEntity> salelist=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .lt("sell_master_date",endtime)
                        .ge("sell_master_date",beginTime)
                        .in("shop_code",shopcode)
        );
        for (String time:timelist) {
            Calendar calendara = Calendar.getInstance();
            calendara.setTime(DateUtil.parse(time));
            calendara.add(Calendar.HOUR,-1);
            String timeqian = df.format(calendara.getTime());
            Double count=0D;
            for (JxcSaleOrderEntity sale:salelist) {

                if(timeqian.substring(0,13).equals(df.format(sale.getSellMasterDate()).substring(0,13))){
                    count +=sale.getMobilePay();
                    count +=sale.getCashPay();
                    count +=sale.getBankPay();
                }
            }
           /* if(count >0){
                JxcSaleOrderEntity en=new JxcSaleOrderEntity();
                en.setName(time.substring(11,13));
                en.setYvalue(count);
                list.add(en);
            }*/
            JxcSaleOrderEntity en=new JxcSaleOrderEntity();
            en.setName(time.substring(11,13));
            en.setYVue(count);
            list.add(en);
            //Collections.reverse(list);
        }
        return list;
    }



    @Override
    public List<JxcSaleOrderEntity> hour24Salesvolume(String deptId) {
        List<JxcSaleOrderEntity> list=new ArrayList<>();
        //该部门所有商户
        List<JxcShopEntity> shoplist=jxcShopService.list(
                new QueryWrapper<JxcShopEntity>()
                        .eq("dept_id",deptId)
        );
        List<String> shopcode=new ArrayList<>();//所有商户编码
        for (JxcShopEntity shop:shoplist) {
            shopcode.add(shop.getShopCode());
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        /*****************用来查询的时间**********************/
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());//用来查询
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        String beginTime=df.format(calendar.getTime())+" 00:00:00";//24小时前的时间

        //24小时所有销售记录
        List<JxcSaleOrderEntity> salelist=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .ge("sell_master_date",beginTime)
                        .in("shop_code",shopcode)
        );
        for (JxcShopEntity shop:shoplist) {
            int count=0;
            for (JxcSaleOrderEntity order:salelist) {
                if(order.getShopCode().equals(shop.getShopCode())){
                    count +=order.getTotalAmount();
                }
            }
            JxcSaleOrderEntity en=new JxcSaleOrderEntity();
            en.setName(shop.getShopName());
            en.setYvalue(count);
            list.add(en);
        }
            return list;
    }

    @Override
    public List<JxcSaleOrderEntity> realtimeorder() {
        List<JxcShopEntity> shoplist=jxcShopService.list(
                new QueryWrapper<JxcShopEntity>()
                .eq("status","0")
        );
        List<JxcSaleOrderEntity> list=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                .orderByDesc("sell_master_date")
                .last(" limit 20")
        );
        for (JxcSaleOrderEntity en:list) {
            for (JxcShopEntity shop:shoplist) {
                if(shop.getShopCode().equals(en.getShopCode())){
                    if("3".equals(shop.getDeptId())){
                        en.setName("南区");
                    }else if("4".equals(shop.getDeptId())){
                        en.setName("北区");
                    }
                }
            }
        }
        return list;
    }

    @Override
    public List<JxcSellDetailsEntity> detailist() {
        //最新一条订单
        List<JxcSaleOrderEntity> list=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                .orderByDesc("sell_master_date")
                .last("limit 1")
        );
        String orderid=list.get(0).getSellMasterCode();
        List<JxcSellDetailsEntity> detail=sellDetailsService.list(
                new QueryWrapper<JxcSellDetailsEntity>()
                .eq("sell_master_code",orderid)
        );
        return detail;
    }

    @Override
    public List<JxcSellDetailsEntity> rllandprice() {
        List<JxcSellDetailsEntity> list=new ArrayList<>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Date date=new Date();
        /*****************用来查询的时间**********************/
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(date);
        calendar1.add(Calendar.DAY_OF_MONTH, -1);
        calendar1.set(Calendar.MINUTE, 0);
        calendar1.set(Calendar.SECOND, 0);
        calendar1.set(Calendar.MILLISECOND, 0);
        String beginTime=df.format(calendar1.getTime());//24小时前的时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, 1);//1小时后
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String endtime=df.format(calendar.getTime());//1小时后的时间
        /*****************用来查询的时间**********************/
        List<String> timelist=new ArrayList<>();
        for (int i = 0; i <24; i++) {//将时间段都放入集合中
            Calendar calendar2=Calendar.getInstance();
            calendar2.setTime(date);
            calendar2.add(Calendar.HOUR_OF_DAY, -i);
            timelist.add(df.format(calendar2.getTime()));
        }

        //所有卡口 去除厕所
        List<RllPlaceEntity> placelist=rllPlaceService.list(
                new QueryWrapper<RllPlaceEntity>()
                        .eq("type","0")
        );
        List<String> placeid=new ArrayList<>();
        for (RllPlaceEntity place:placelist) {
            placeid.add(place.getId());
        }
        //该时间段的客流量
        List<RllHourCountEntity> rllcountlist=rllHourCountService.list(
                new QueryWrapper<RllHourCountEntity>()
                        .ge("start_time",beginTime)
                        .lt("start_time",endtime)
                        .in("place_id",placeid)
        );
        //该时间段的销售额
        List<JxcSellDetailsEntity> selllist=sellDetailsService.list(
                new QueryWrapper<JxcSellDetailsEntity>()
                        .ge("sell_master_date",beginTime)
                        .lt("sell_master_date",endtime)
        );
        for (String time:timelist) {
            int scount=0;
            int rcount=0;
            for (JxcSellDetailsEntity sale:selllist) {
                if(time.substring(0,13).equals(df.format(sale.getSellMasterDate()).substring(0,13))){
                    scount +=sale.getSellAmount();
                }
            }
            for (RllHourCountEntity rll:rllcountlist) {
                if(time.substring(0,13).equals(df.format(rll.getStartTime()).substring(0,13))){
                    rcount +=rll.getEnterNum();
                }
            }

            DecimalFormat dff=new DecimalFormat("0.00");//设置保留位数
            String a= dff.format((float)scount/rcount);
            JxcSellDetailsEntity en=new JxcSellDetailsEntity();
            en.setYValue(time.substring(11,13));
            en.setName(a);
            list.add(en);
        }
        return list;
    }


    @Override
    public void getSellMasterByCode(String startDate) throws ParseException {
        List<String> codeList=new ArrayList<>();
        Map maps=SellMasterUtil.getSellMaster(startDate);
        if(maps!=null){
            JSONArray datas = (JSONArray) JSON.parse(maps.get("Data").toString());
            for(int i = 0;i < datas.size();i++){
                JSONObject job = datas.getJSONObject(i);
                String sellMasterCode=job.get("SellMasterCode").toString();
                codeList.add(sellMasterCode);
                if(!SellMasterUtil.sellMasterCodeList.contains(sellMasterCode)){
                    JxcSaleOrderEntity saleOrder=new JxcSaleOrderEntity();
                    saleOrder.setShopCode(job.get("ShopCode").toString());
                    saleOrder.setShopName(job.get("ShopName").toString());
                    saleOrder.setMachineCode(job.get("MachineCode").toString());
                    saleOrder.setMachineCode(job.get("MachineCode").toString());
                    saleOrder.setSellWorkerCode(job.get("SellWorkerCode").toString());
                    saleOrder.setSellWorerName(job.get("SellWorerName").toString());
                    saleOrder.setSellMasterCode(sellMasterCode);
                    saleOrder.setTotalCount(new Double(Double.parseDouble(job.get("TotalCount").toString())).longValue());
                    saleOrder.setTotalAmount(Double.parseDouble(job.get("TotalAmount").toString()));
                    saleOrder.setTotalDiscount(Double.parseDouble(job.get("TotalDiscount").toString()));
                    saleOrder.setCashPay(Double.parseDouble(job.get("CashPay").toString()));
                    saleOrder.setBankPay(Double.parseDouble(job.get("BankPay").toString()));
                    saleOrder.setMobilePay(Double.parseDouble(job.get("MobilePay").toString()));
                    saleOrder.setSellMasterDate(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(job.get("SellMasterDate").toString()));
                    JSONArray sellDetails = (JSONArray) JSON.parse(job.get("SellDetails").toString());
                    List<JxcSellDetailsEntity> sellDetailsList=new ArrayList<>();
                    for (int j = 0; j <sellDetails.size(); j++) {
                        JSONObject sell = sellDetails.getJSONObject(j);
                        JxcSellDetailsEntity sellDetailsEntity=new JxcSellDetailsEntity();
                        sellDetailsEntity.setSellMasterCode(saleOrder.getSellMasterCode());
                        sellDetailsEntity.setSellMasterDate(saleOrder.getSellMasterDate());
                        sellDetailsEntity.setCommodityBarcode(sell.get("CommodityBarcode").toString());
                        sellDetailsEntity.setCommodityName(sell.get("CommodityName").toString());
                        sellDetailsEntity.setSellCount(new Double(Double.parseDouble(sell.get("SellCount").toString())).longValue());
                        sellDetailsEntity.setPrice(Double.parseDouble(sell.get("Price").toString()));
                        sellDetailsEntity.setDiscount(Double.parseDouble(sell.get("Discount").toString()));
                        sellDetailsEntity.setSellAmount(Double.parseDouble(sell.get("SellAmount").toString()));
                        sellDetailsList.add(sellDetailsEntity);
                    }
                    this.save(saleOrder);
                    sellDetailsService.saveBatch(sellDetailsList);
                }

            }
            SellMasterUtil.sellMasterCodeList=codeList;
        }
    }

    @Override
    public JxcSaleOrderEntity xseTodayCount(String startTime) {
        return this.baseMapper.xseTodayCount(startTime);
    }

    @Override
    public List<JxcSaleOrderEntity> xlChart(String startTime, String endTime, List<String> shopCodeList) {
        return this.baseMapper.xlChart(startTime,endTime,shopCodeList);
    }

    @Override
    public List<JxcSaleOrderEntity> hour24Sale(String deptId) {
        List<JxcSaleOrderEntity> list=new ArrayList<>();
        //该部门所有商户
        List<JxcShopEntity> shoplist=jxcShopService.list(
                new QueryWrapper<JxcShopEntity>()
                .eq("dept_id",deptId)
        );
        List<String> shopcode=new ArrayList<>();//所有商户编码
        for (JxcShopEntity shop:shoplist) {
            shopcode.add(shop.getShopCode());
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        Date date=new Date();
        List<String> timelist=new ArrayList<>();
        for (int i = 0; i <24; i++) {//将时间段都放入集合中
            Calendar calendar=Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.HOUR_OF_DAY, -i);//i小时后
            timelist.add(df.format(calendar.getTime()));
        }

        /*****************用来查询的时间**********************/
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(date);
        calendar1.add(Calendar.DAY_OF_MONTH, -1);
        calendar1.set(Calendar.MINUTE, 0);
        calendar1.set(Calendar.SECOND, 0);
        calendar1.set(Calendar.MILLISECOND, 0);
        String beginTime=df.format(calendar1.getTime());//24小时前的时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, 1);//1小时后
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String endtime=df.format(calendar.getTime());//1小时后的时间
        /*****************用来查询的时间**********************/
        //24小时内的所有销售数据
        List<JxcSaleOrderEntity> salelist=this.list(
                new QueryWrapper<JxcSaleOrderEntity>()
                        .lt("sell_master_date",endtime)
                        .ge("sell_master_date",beginTime)
                        .in("shop_code",shopcode)
        );
        for (String time:timelist) {
            int count=0;
            for (JxcSaleOrderEntity sale:salelist) {
                    if(time.substring(0,13).equals(df.format(sale.getSellMasterDate()).substring(0,13))){
                        count +=sale.getTotalAmount();
                    }
            }
           /* if(count >0){
                JxcSaleOrderEntity en=new JxcSaleOrderEntity();
                en.setName(time.substring(11,13));
                en.setYvalue(count);
                list.add(en);
            }*/
            JxcSaleOrderEntity en=new JxcSaleOrderEntity();
            en.setName(time.substring(11,13));
            en.setYvalue(count);
            list.add(en);
            //Collections.reverse(list);
        }
        return list;
    }


}
